/*******************************************************************
 *
 * Copyright (C), 2021-2022, LS, All rights reserved.
 *
 * Author      : 
 * Create Time : 2021-09-22
 * Version     : v0.1
 * Description : 
 *******************************************************************/
 
/*----------------------------Head file----------------------------*/
#include "OSAL.h"
#include "osal_app.h"
#include "sys_task.h"
#include "app_misc.h"
#include "app_reset.h"
#include "app_battery.h"
#include "app_display.h"
#include "app_store_mem.h"
#include "app_global_data.h"
#include "app_store_set_info.h"
#include "bsp_hw_config.h"
#include "ble_app_util.h"

#include "ls_ble_custom_api.h"

/*----------------------------macro file---------------------------*/
#define BG_EVT_LOG_ENABLE   1

#if BG_EVT_LOG_ENABLE
#include "log.h"
#define BG_EVT_LOG          LOG
#else
#define BG_EVT_LOG(...)
#endif

/*----------------------------type define--------------------------*/

/*----------------------------var define---------------------------*/

/*-------------------------func declaration------------------------*/

/*-----------------------------------------------------------------*/

void sys_background_evt_handle(uint8_t evt)
{
    switch(evt)
    {
        case BG_EVT_BAT_ADC_CONVERT_DONE: {
            app_batt_adc_read_done_handle();
        } break;
        
        case BG_EVT_STORE_MEM_ERR_HDL: {
            BG_EVT_LOG("SYS_EVT_STORE_MEM_ERR_HDL\n");
            app_mem_data_clear_all();
        } break;
        
        case BG_EVT_BLE_UPLOAD_BATT_PER: {
            BG_EVT_LOG("SYS_EVT_BLE_UPLOAD_BATT_PER\n");
            app_ble_upload_batt_per();
        } break;
        
        case BG_EVT_BLE_UPLOAD_MEM: {
            BG_EVT_LOG("SYS_EVT_BLE_UPLOAD_MEM\n");
            if(SKIP_MODE_CUMULATIVE_NUM != g_app_data.tmp.skip.mode) {
                app_ble_upload_skip_result();
            }
        } break;
        
        case BG_EVT_SHIP_MODE_ENTER: {
            BG_EVT_LOG("SYS_EVT_SHIP_MODE_ENTER.\n");
            app_ship_mode_enter();
        } break;
        
        case BG_EVT_BLE_DEV_RESET: {
            ls_ble_custom_send_msg(SKIP_CMD_DEV_RESET);
            app_delay_reset(false);
        } break;
        
        case BG_EVT_BLE_DEV_REVERT: {
            ls_ble_custom_send_msg(SKIP_CMD_DEV_REVERT);
            app_delay_reset(true);
        } break;
        
        case BG_EVT_BLE_SET_ADV_NAME: {
            ls_ble_custom_send_msg(SKIP_CMD_SET_ADV_NAME);
        } break;

        default:
            break;
    }
}

